<?php


/**
 * Description of tasks
 *
 * @author David Morris
 */
class Tasks extends CI_Controller
{
    private $data = array();
    
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->helper('url');
        $this->load->model('TaskModel');
        $this->data = array(
            'parentTask' => array('0' => 'No Parent Task') + $this->TaskModel->getTasksAsArray(),
            'project' => array('0' => 'No Project'),
            'priority'   => array_combine(array_values(range(1,5)), range(1,5))
        );
    }
    
    public function index()
    {

        if($this->input->post('add-task'))
        {
            // TODO set task_creator to be user's id.
            $this->TaskModel->updateAll($this->input->post(null,false))->insert();
        }
        $this->load->view('tasks_add_form', $this->data);
    }
    
    public function edit($id = null)
    {
        if(!is_numeric($id))
            redirect('Tasks/');
        
        $data = $this->data;
        $data['edit'] = $this->TaskModel->getWhere('task_id = '.$id);
        $data['edit'] = $data['edit'][0];
        $this->load->view('tasks_add_form', $data);
        
    }
    
    
    public function view($id)
    {
        if(!is_numeric)
            throw new Exception("No valid id for task provided");
        
    }
    
    public function delete()
    {
        
    }
    
    public function test()
    {
        $query = $this->TaskModel->returnUsers(5);
        $this->load->view('tasks_view');
    }
}

?>
